home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / diropus4.12b_gpl / library / simplerequest.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  16KB  |  541 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32.  
  33. char *get_uscore_text(struct DOpusRemember **,char *,int);
  34.  
  35. static char *contstring[]={"_Continue"};
  36.  
  37. __asm __saveds DoDoSimpleRequest(register __a0 struct Window *window,
  38.     register __a1 struct DOpusSimpleRequest *simple)
  39. {
  40.     int
  41.         textlen,a,b,c,cw,cy,cb,sw,height,maxlen,llen,num,gwidth=0,gspace,gx,ty,ac,ogy,
  42.         gadgetid,ls,gy,last,gnum,lines,dl,strgad,sfy,hnum,rows=1,macc,ogx,
  43.         maxwidth,winwidth,winheight,xoffset,yoffset,d;
  44.     struct NewWindow *newwindow;
  45.     struct DOpusRemember *key;
  46.     struct Gadget *gadgets,*contgad,*gad,*glassgad=NULL;
  47.     struct Screen *screen;
  48.     struct Window *Window;
  49.     struct RastPort *rp,testrp;
  50.     struct TextFont *fnt,*tfnt;
  51.     struct StringInfo *sinfo;
  52.     struct IntuiMessage *Msg;
  53.     struct StringExtend *extend;
  54.     char *text,*keys,*buf,ch,*strbuf,**gadptr;
  55.     ULONG class;
  56.     USHORT code;
  57.  
  58.     if (!simple) return(0);
  59.     if (!window) {
  60.         screen=IntuitionBase->FirstScreen;
  61.         fnt=GfxBase->DefaultFont;
  62.     }
  63.     else {
  64.         screen=window->WScreen;
  65.         fnt=window->RPort->Font;
  66.     }
  67.     if (simple->font) fnt=simple->font;
  68.     if (IntuitionBase->LibNode.lib_Version>36) tfnt=fnt;
  69.     else tfnt=screen->RastPort.Font;
  70.     InitRastPort(&testrp);
  71.     SetFont(&testrp,fnt);
  72.  
  73.     if (simple->flags&SRF_BORDERS) maxwidth=screen->Width-screen->WBorLeft-screen->WBorRight;
  74.     else maxwidth=screen->Width;
  75.  
  76.     ac=macc=0;
  77.     for (a=0,num=0,hnum=0;;a++) {
  78.         if (!simple->gads[a]) break;
  79.         if (simple->gads[a][0]) {
  80.             if (simple->gads[a][0]=='\n') {
  81.                 ++rows;
  82.                 ++hnum;
  83.                 if (ac>macc) macc=ac;
  84.                 ac=0;
  85.             }
  86.             else {
  87.                 if ((b=TextLength(&testrp,simple->gads[a],strlen(simple->gads[a]))+fnt->tf_XSize)>gwidth)
  88.                     gwidth=b;
  89.                 ++num; ++ac;
  90.             }
  91.         }
  92.         else {
  93.             ++hnum;
  94.             ++ac;
  95.         }
  96.     }
  97.     gnum=num;
  98.     if (simple->strbuf) ++num;
  99.     if (ac>macc) macc=ac;
  100.  
  101.     key=NULL; textlen=strlen(simple->text);
  102.  
  103.     cw=fnt->tf_XSize; cy=fnt->tf_YSize; cb=fnt->tf_Baseline;
  104.     sw=(maxwidth/cw)-2; sfy=tfnt->tf_YSize;
  105.  
  106.     if (!(text=(char *)LAllocRemember(&key,textlen+2,MEMF_CLEAR)) ||
  107.         !(keys=(char *)LAllocRemember(&key,gnum,MEMF_CLEAR)) ||
  108.         !(newwindow=(struct NewWindow *)LAllocRemember(&key,sizeof(struct NewWindow),MEMF_CLEAR)) ||
  109.         !(gadgets=(struct Gadget *)LAllocRemember(&key,sizeof(struct Gadget)*(num+1),MEMF_CLEAR)) ||
  110.         !(contgad=(struct Gadget *)LAllocRemember(&key,sizeof(struct Gadget),MEMF_CLEAR)) ||
  111.         !(gadptr=(char **)LAllocRemember(&key,(num+hnum+1)*4,MEMF_CLEAR)) ||
  112.         !(buf=(char *)LAllocRemember(&key,sw+2,0))) {
  113.         LFreeRemember(&key);
  114.         return(0);
  115.     }
  116.  
  117.     if (simple->strbuf) {
  118.         if (!(sinfo=(struct StringInfo *)LAllocRemember(&key,sizeof(struct StringInfo),MEMF_CLEAR)) ||
  119.             !(extend=(struct StringExtend *)LAllocRemember(&key,sizeof(struct StringExtend),MEMF_CLEAR)) ||
  120.             !(strbuf=(char *)LAllocRemember(&key,simple->strlen+1,MEMF_CLEAR))) {
  121.             LFreeRemember(&key);
  122.             return(0);
  123.         }
  124.         strcpy(strbuf,simple->strbuf);
  125.         if (simple->flags&SRF_GLASS)
  126.             glassgad=LAllocRemember(&key,sizeof(struct Gadget),MEMF_CLEAR);
  127.     }
  128.  
  129.     CopyMem(simple->text,text,textlen);
  130.     if (text[textlen-1]!=10) {
  131.         text[textlen]=10;
  132.         ++textlen;
  133.     }
  134.  
  135.     height=maxlen=llen=ls=0;
  136.     for (a=0;a<textlen;a++) {
  137.         if (text[a]==10 || llen==sw) {
  138.             b=a;
  139.             if (llen==sw) {
  140.                 while (a>ls) {
  141.                     if (text[a]==' ' || text[a]=='.' || text[a]==',') {
  142.                         llen=a-ls;
  143.                         text[a]=10;
  144.                         break;
  145.                     }
  146.                     --a; --llen;
  147.                 }
  148.                 if (a==ls) {
  149.                     a=b;
  150.                     llen=a-ls;
  151.                 }
  152.             }
  153.             height+=cy+1;
  154.             if ((llen=TextLength(&testrp,&text[ls],llen)+fnt->tf_XSize)>maxlen)
  155.                 maxlen=llen;
  156.             llen=0; ls=a;
  157.         }
  158.         else ++llen;
  159.     }
  160.  
  161.     if (gwidth<100) gwidth=100;
  162.     if (gwidth*macc>maxwidth) {
  163.         hnum=0;
  164.         gwidth=(gnum)?maxwidth/gnum:0;
  165.     }
  166.  
  167.     newwindow->DetailPen=255;
  168.     newwindow->BlockPen=255;
  169.     newwindow->IDCMPFlags=IDCMP_GADGETUP|IDCMP_VANILLAKEY|IDCMP_MOUSEBUTTONS;
  170.     newwindow->Flags=WFLG_ACTIVATE|WFLG_BORDERLESS|WFLG_RMBTRAP;
  171.     newwindow->Type=CUSTOMSCREEN;
  172.  
  173.     if (simple->flags&SRF_BORDERS) {
  174.         xoffset=screen->WBorLeft;
  175.         yoffset=screen->WBorTop+screen->Font->ta_YSize+1;
  176.         newwindow->Title=simple->title;
  177.     }
  178.     else {
  179.         xoffset=0;
  180.         yoffset=0;
  181.     }
  182.  
  183.     newwindow->Width=maxlen+8;
  184.     a=(gwidth*macc)+((macc+2)*10);
  185.     if (simple->strbuf && a<((42*tfnt->tf_XSize)+20)) a=(42*tfnt->tf_XSize)+20;
  186.     if (simple->flags&SRF_BORDERS) {
  187.         newwindow->Width+=screen->WBorLeft+screen->WBorRight;
  188.         a+=screen->WBorLeft+screen->WBorRight;
  189.         newwindow->Flags=WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_DRAGBAR|WFLG_DEPTHGADGET;
  190.     }
  191.     if (newwindow->Width<a) newwindow->Width=a;
  192.     if (newwindow->Width>screen->Width) newwindow->Width=screen->Width;
  193.  
  194.     newwindow->Height=height+16+(num?((cy+5)*rows):0);
  195.     if (simple->flags&SRF_BORDERS) newwindow->Height+=yoffset+screen->WBorBottom;
  196.     if (simple->strbuf) newwindow->Height+=sfy+4;
  197.     if (newwindow->Height>screen->Height) newwindow->Height=screen->Height;
  198.  
  199.     if (window) {
  200.         newwindow->LeftEdge=window->LeftEdge+((window->Width-newwindow->Width)/2);
  201.         newwindow->TopEdge=window->TopEdge+((window->Height-newwindow->Height)/2);
  202.     }
  203.     else {
  204.         newwindow->LeftEdge=(screen->Width-newwindow->Width)/2;
  205.         newwindow->TopEdge=(screen->Height-newwindow->Height)/2;
  206.     }
  207.  
  208.     if (newwindow->LeftEdge+newwindow->Width>screen->Width)
  209.         newwindow->LeftEdge=screen->Width-newwindow->Width;
  210.     if (newwindow->TopEdge+newwindow->Height>screen->Height)
  211.         newwindow->TopEdge=screen->Height-newwindow->Height;
  212.     if (newwindow->LeftEdge<0) newwindow->LeftEdge=0;
  213.     if (newwindow->TopEdge<0) newwindow->TopEdge=0;
  214.  
  215.     newwindow->Screen=screen;
  216.  
  217.     winwidth=newwindow->Width;
  218.     winheight=newwindow->Height;
  219.  
  220.     if (simple->flags&SRF_BORDERS) {
  221.         winwidth-=screen->WBorLeft+screen->WBorRight;
  222.         winheight-=yoffset+screen->WBorBottom;
  223.     }
  224.  
  225.     ogx=gx=(winwidth-(gwidth*macc))/(macc+1);
  226.     gspace=gx+gwidth;
  227.  
  228.     ogy=gy=winheight-4-(num?((cy+5)*rows):0);
  229.     if (simple->strbuf) lines=(gy-(sfy+8)-(7+cb))/(cy+1);
  230.     else lines=(gy-(7+cb))/(cy+1);
  231.  
  232.     last=a=0; strgad=1;
  233.     for (b=0;b<(num+hnum);b++) {
  234.         if (last && simple->strbuf) {
  235.             gadgets[a].LeftEdge=10+cw+xoffset;
  236.             c=cb+7+(lines*cy);
  237.             gadgets[a].TopEdge=c+(((ogy-c)-sfy)/2)+yoffset+1;
  238.             gadgets[a].Width=winwidth-20-(cw*2);
  239.             gadgets[a].Height=sfy;
  240.             gadgets[a].Flags=GFLG_GADGHCOMP|GFLG_STRINGEXTEND;
  241.             gadgets[a].Activation=GACT_RELVERIFY|GACT_TOGGLESELECT;
  242.             if (simple->flags&SRF_LONGINT) gadgets[a].Activation|=LONGINT;
  243.             if (simple->flags&SRF_CENTJUST) gadgets[a].Activation|=STRINGCENTER;
  244.             if (simple->flags&SRF_RIGHTJUST) gadgets[a].Activation|=STRINGRIGHT;
  245.             gadgets[a].GadgetType=GTYP_STRGADGET;
  246.             gadgets[a].GadgetID=65535;
  247.             gadgets[a].SpecialInfo=(APTR)sinfo;
  248.             sinfo->Buffer=strbuf;
  249.             sinfo->UndoBuffer=LAllocRemember(&key,simple->strlen+2,MEMF_CLEAR);
  250.             sinfo->MaxChars=simple->strlen+1;
  251.  
  252.             if (simple->flags&SRF_EXTEND)
  253.                 CopyMem((char *)simple->value,(char *)extend,sizeof(struct StringExtend));
  254.             else {
  255.                 extend->Font=fnt;
  256.                 extend->Pens[0]=simple->fg;
  257.                 extend->Pens[1]=simple->bg;
  258.                 extend->ActivePens[0]=simple->fg;
  259.                 extend->ActivePens[1]=simple->bg;
  260.             }
  261.             sinfo->Extension=extend;
  262.  
  263.             strgad=a;
  264.             if (glassgad) {
  265.                 gadgets[a].LeftEdge+=24;
  266.                 gadgets[a].Width-=24;
  267.  
  268.                 glassgad->LeftEdge=4+cw+xoffset;
  269.                 glassgad->TopEdge=gadgets[a].TopEdge-2;
  270.                 glassgad->Width=24;
  271.                 glassgad->Height=sfy+4;
  272.                 glassgad->Flags=GFLG_GADGHCOMP;
  273.                 glassgad->Activation=GACT_RELVERIFY;
  274.                 glassgad->GadgetType=GTYP_BOOLGADGET;
  275.                 glassgad->GadgetID=65534;
  276.             }
  277.         }
  278.         else if (simple->gads[b][0]) {
  279.             if (simple->gads[b][0]=='\n') {
  280.                 gy+=cy+6;
  281.                 gx=ogx-gspace;
  282.             }
  283.             else if (a<gnum) {
  284.                 gadgets[a].LeftEdge=gx+xoffset;
  285.                 gadgets[a].TopEdge=gy+yoffset;
  286.                 gadgets[a].Width=gwidth;
  287.                 gadgets[a].Height=cy+5;
  288.                 gadgets[a].Flags=GADGHCOMP;
  289.                 gadgets[a].Activation=RELVERIFY;
  290.                 gadgets[a].GadgetType=GTYP_BOOLGADGET;
  291.                 gadgets[a].GadgetID=simple->rets[a];
  292.                 d=0;
  293.                 keys[a]=LToLower(simple->gads[b][0]);
  294.                 for (c=0;c<a;c++) {
  295.                     if (keys[c]==keys[a]) {
  296.                         keys[a]=LToLower(simple->gads[b][1]);
  297.                         d=1;
  298.                         break;
  299.                     }
  300.                 }
  301.                 gadptr[a]=get_uscore_text(&key,simple->gads[b],(simple->strbuf)?-1:d);
  302.                 if (last) break;
  303.                 if (a==gnum-1 && simple->strbuf) last=1;
  304.                 ++a;
  305.             }
  306.         }
  307.         if ((gx+=gspace)>winwidth) {
  308.             num=a+1;
  309.             if (simple->strbuf) {
  310.                 last=1;
  311.                 ++num;
  312.             }
  313.             else if (a<num) break;
  314.         }
  315.     }
  316.  
  317.     for (a=0;a<num;a++) gadgets[a].NextGadget=(a<num-1)?&gadgets[a+1]:NULL;
  318.  
  319.     contgad->Width=(cw*10)<100?100:cw*10;
  320.     contgad->LeftEdge=(newwindow->Width-contgad->Width)/2;
  321.     contgad->TopEdge=gy+yoffset;
  322.     contgad->Height=cy+4;
  323.     contgad->Flags=GFLG_GADGHCOMP; contgad->Activation=GACT_RELVERIFY;
  324.     contgad->GadgetType=GTYP_BOOLGADGET;
  325.  
  326.     if (num && (simple->flags&SRF_RECESSHI))
  327.         DoAddGadgetBorders(&key,contgad,1,simple->hi,simple->lo);
  328.  
  329.     if (!(Window=OpenWindow(newwindow))) {
  330.         LFreeRemember(&key);
  331.         return(0);
  332.     }
  333.     rp=Window->RPort;
  334.     SetFont(rp,fnt);
  335.  
  336.     if ((screen->Flags&15)==CUSTOMSCREEN)
  337.         ModifyIDCMP(Window,GADGETUP|VANILLAKEY|INACTIVEWINDOW|MOUSEBUTTONS);
  338.  
  339.     if (simple->hi==-1) simple->hi=2;
  340.     if (simple->lo==-1) simple->lo=1;
  341.     if (simple->fg==-1) simple->fg=1;
  342.     if (simple->bg==-1) simple->bg=0;
  343.  
  344.     if (!(simple->flags&SRF_BORDERS))
  345.         Do3DBox(rp,2,1,Window->Width-4,Window->Height-2,simple->hi,simple->lo);
  346.  
  347.     SetAPen(rp,simple->bg);
  348.     RectFill(rp,xoffset+2,yoffset+1,xoffset+winwidth-3,yoffset+winheight-2);
  349.     SetAPen(rp,simple->fg); SetBPen(rp,simple->bg);
  350.  
  351.     ty=7+cb+yoffset;
  352.     llen=dl=0;
  353.     for (a=0;a<textlen;a++) {
  354.         buf[llen]=text[a];
  355.         if (text[a]==10 || llen==sw) {
  356.             if (simple->flags&SRF_NOCENTER) Move(rp,Window->BorderLeft+6,ty);
  357.             else Move(rp,(Window->Width-(TextLength(rp,buf,llen)))/2,ty);
  358.             Text(rp,buf,llen);
  359.             llen=0; ty+=cy+1; ++dl;
  360.             if (dl>lines && a<textlen-1) {
  361.                 dl=0;
  362.                 if (num) DoAddGadgets(Window,contgad,contstring,1,simple->hi,simple->lo,1);
  363.                 c=0;
  364.                 FOREVER {
  365.                     Wait(1<<Window->UserPort->mp_SigBit);
  366.                     while (Msg=(struct IntuiMessage *)GetMsg(Window->UserPort)) {
  367.                         class=Msg->Class; code=Msg->Code;
  368.                         if (class==IDCMP_GADGETUP)
  369.                             gadgetid=((struct Gadget *)Msg->IAddress)->GadgetID;
  370.                         ReplyMsg((struct Message *)Msg);
  371.                         if (class==IDCMP_INACTIVEWINDOW) {
  372.                             if (IntuitionBase->ActiveScreen==screen) ActivateWindow(Window);
  373.                         }
  374.                         else if (num) {
  375.                             if (class==IDCMP_VANILLAKEY) {
  376.                                 ch=LToLower(code);
  377.                                 if (ch=='\r' || ch=='c') {
  378.                                     c=1;
  379.                                     SelectGadget(Window,contgad);
  380.                                     break;
  381.                                 }
  382.                                 if (ch=='') {
  383.                                     CloseWindow(Window);
  384.                                     LFreeRemember(&key);
  385.                                     return(0);
  386.                                 }
  387.                             }
  388.                             else if (class==IDCMP_GADGETUP) {
  389.                                 c=1;
  390.                                 break;
  391.                             }
  392.                         }
  393.                         else if (!num && class==IDCMP_MOUSEBUTTONS && code==SELECTDOWN) c=1;
  394.                     }
  395.                     if (c) break;
  396.                 }
  397.                 if (num) RemoveGList(Window,contgad,1);
  398.                 SetAPen(rp,simple->bg);
  399.                 RectFill(rp,xoffset+2,yoffset+1,xoffset+winwidth-3,yoffset+winheight-2);
  400.                 SetAPen(rp,simple->fg);
  401.                 SetBPen(rp,simple->bg);
  402.                 ty=7+cb+yoffset;
  403.             }
  404.         }
  405.         else ++llen;
  406.     }
  407.  
  408.     if (num) {
  409.         if (simple->flags&SRF_RECESSHI)
  410.             DoAddGadgetBorders(&key,gadgets,num,simple->hi,simple->lo);
  411.         DoAddGadgets(Window,gadgets,gadptr,num,simple->hi,simple->lo,1);
  412.     }
  413.     if (simple->strbuf) {
  414.         SetAPen(rp,0);
  415.         RectFill(rp,gadgets[strgad].LeftEdge,gadgets[strgad].TopEdge,
  416.             gadgets[strgad].LeftEdge+gadgets[strgad].Width-1,
  417.             gadgets[strgad].TopEdge+gadgets[strgad].Height-1);
  418.         Delay(5);
  419.         ActivateStrGad(&gadgets[strgad],Window);
  420.         if (glassgad) {
  421.             if (simple->flags&SRF_RECESSHI)
  422.                 DoAddGadgetBorders(&key,glassgad,1,simple->hi,simple->lo);
  423.             DoAddGadgets(Window,glassgad,NULL,1,simple->hi,simple->lo,1);
  424.             DoDoGlassImage(rp,glassgad,simple->hi,simple->lo,0);
  425.         }
  426.     }
  427.  
  428.     FOREVER {
  429.         Wait(1<<Window->UserPort->mp_SigBit);
  430.         while (Msg=(struct IntuiMessage *)GetMsg(Window->UserPort)) {
  431.             class=Msg->Class; code=Msg->Code;
  432.             if (class==GADGETUP) {
  433.                 gad=(struct Gadget *)Msg->IAddress;
  434.                 gadgetid=gad->GadgetID;
  435.             }
  436.             ReplyMsg((struct Message *)Msg);
  437.             switch (class) {
  438.                 case MOUSEBUTTONS:
  439.                     if (!num && (code==MENUDOWN || code==SELECTDOWN)) {
  440.                         CloseWindow(Window);
  441.                         LFreeRemember(&key);
  442.                         return(1);
  443.                     }
  444.                     if (simple->strbuf) ActivateStrGad(&gadgets[strgad],Window);
  445.                     break;
  446.                 case INACTIVEWINDOW:
  447.                     if (IntuitionBase->ActiveScreen==screen) {
  448.                         ActivateWindow(Window);
  449.                         if (simple->strbuf) {
  450.                             Delay(5);
  451.                             ActivateStrGad(&gadgets[strgad],Window);
  452.                         }
  453.                     }
  454.                     break;
  455.                 case VANILLAKEY:
  456.                     ch=LToLower(code);
  457.                     if (ch=='' || ch=='\r') {
  458.                         if (ch=='') a=0;
  459.                         else a=1;
  460.                         for (gadgetid=0;gadgetid<gnum;gadgetid++)
  461.                             if (simple->rets[gadgetid]==a) break;
  462.                         if (simple->rets[gadgetid]!=a) break;
  463.                     }
  464.                     else {
  465.                         for (gadgetid=0;gadgetid<gnum;gadgetid++)
  466.                             if (ch==keys[gadgetid]) break;
  467.                         if (ch!=keys[gadgetid]) break;
  468.                     }
  469.                     if (gadgetid>=gnum) gadgetid=gnum-1;
  470.                     if (gadgets[gadgetid].Activation&TOGGLESELECT) {
  471.                         HiliteGad(&gadgets[gadgetid],rp);
  472.                         gadgetid=gad->GadgetID;
  473.                     }
  474.                     else {
  475.                         SelectGadget(Window,&gadgets[gadgetid]);
  476.                         gadgetid=simple->rets[gadgetid];
  477.                     }
  478.                 case GADGETUP:
  479.                     if (simple->strbuf && gadgetid==65534) {
  480.                         struct DOpusFileReq filereq;
  481.                         char dirbuf[256],filebuf[32],*ptr;
  482.  
  483.                         filereq.title="Select directory";
  484.                         filereq.dirbuf=dirbuf;
  485.                         filereq.filebuf=filebuf;
  486.                         filereq.window=Window;
  487.                         filereq.x=-2;
  488.                         filereq.y=-2;
  489.                         filereq.lines=15;
  490.                         if (simple->flags&SRF_DIRGLASS) filereq.flags=DFRF_DIRREQ;
  491.                         else filereq.flags=0;
  492.                         filereq.filearraykey=NULL;
  493.  
  494.                         strcpy(dirbuf,strbuf);
  495.                         if (!(simple->flags&SRF_DIRGLASS)) {
  496.                             if ((ptr=BaseName(dirbuf))>dirbuf) {
  497.                                 strcpy(filebuf,ptr);
  498.                                 *ptr=0;
  499.                             }
  500.                             else if (CheckExist(dirbuf,NULL)<1) {
  501.                                 dirbuf[0]=0;
  502.                                 strcpy(filebuf,strbuf);
  503.                             }
  504.                             else filebuf[0]=0;
  505.                         }
  506.                         if (FileRequest(&filereq)) {
  507.                             strcpy(strbuf,dirbuf);
  508.                             if (!(simple->flags&SRF_DIRGLASS))
  509.                                 TackOn(strbuf,filebuf,256);
  510.                         }
  511.                         RefreshStrGad(&gadgets[strgad],Window);
  512.                         ActivateStrGad(&gadgets[strgad],Window);
  513.                         break;
  514.                     }
  515.                     CloseWindow(Window);
  516.                     if (gadgetid && simple->strbuf) strcpy(simple->strbuf,strbuf);
  517.                     LFreeRemember(&key);
  518.                     return(gadgetid);
  519.             }
  520.         }
  521.     }
  522. }
  523.  
  524. char *get_uscore_text(key,text,pos)
  525. struct DOpusRemember **key;
  526. char *text;
  527. int pos;
  528. {
  529.     char *newtext;
  530.     int a,len,cp;
  531.  
  532.     len=strlen(text);
  533.     if (!(newtext=LAllocRemember(key,len+2,0))) return(text);
  534.     for (a=0,cp=0;a<len;a++) {
  535.         if (cp==pos) newtext[cp++]='_';
  536.         newtext[cp++]=text[a];
  537.     }
  538.     newtext[cp]=0;
  539.     return(newtext);
  540. }
  541.